<?php

namespace common\models\kaoguobao;

use Yii;
use common\models\BaseModels;
use yii\behaviors\TimestampBehavior;

class Order extends BaseModels
{
    const TYPE_KGB     = "kgb";

    const ORDER_STATUS_STAY_PAY     = 0;
    const ORDER_STATUS_PAY_OK       = 1;
    const ORDER_STATUS_UP_PROOF     = 2;
    const ORDER_STATUS_HANDLED      = 3;
    const ORDER_STATUS_PAYMENT      = 5;
    const ORDER_STATUS_CLOSE        = 10;
    const ORDER_STATUS_REFUSE       = -3;
    const ORDER_STATUS_PAYMENT_FAIL = -5;
    const ORDER_STATUS_OVERTIME     = -10;

    const TYPE_IELTS                = 0;
    const TYPE_TOEFL                = 1;
    const TYPE_CET4                 = 2;
    const TYPE_CET6                 = 3;

    // 订单状态
    public static $orderStatus = [
        self::ORDER_STATUS_STAY_PAY     => "待付款",
        self::ORDER_STATUS_PAY_OK       => "待赔付",
        self::ORDER_STATUS_UP_PROOF     => "待处理",
        self::ORDER_STATUS_HANDLED      => "已处理",
        self::ORDER_STATUS_PAYMENT      => "已赔付",
        self::ORDER_STATUS_CLOSE        => "已结算",
        self::ORDER_STATUS_REFUSE       => "已拒绝",
        self::ORDER_STATUS_PAYMENT_FAIL => "赔付失败",
        self::ORDER_STATUS_OVERTIME     => "订单取消",
    ];

    const KEY_NAME_KGB          = "kgb";

    public static $keyName = [
        self::KEY_NAME_KGB      => "考过宝",
    ];

    //保障项目
    public static $typeName = [
        self::TYPE_IELTS    => "雅思",
        self::TYPE_TOEFL    => "托福",
        self::TYPE_CET4     => "四级",
        self::TYPE_CET6     => "六级",
    ];

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%order}}';
    }

    /**
     * 切换数据库(测试环境)
     */
    public static function getDb(){
        return Yii::$app->get('db_kgb'); 
    }

    /**
     * 给数据库的处理进行时间的操作
     */
    public function behaviors() {
        return [
            TimestampBehavior::className(),
        ];
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [[  'id',
                'is_valid',
                'order_status',
                'user_id',
                'wechat_id',
                'benefit_id',
                'amount',
                'key',
                'type',
                'remarks',
                'start_time',
                'end_time',
                'created_at',
                'updated_at',
            ], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id'            => Yii::t('app_table', 'ID'),
            'is_valid'      => Yii::t('app_table', '状态'),
            'order_num'     => Yii::t('app_table', '订单号'),
            'order_status'  => Yii::t('app_table', '订单状态'),
            'user_id'       => Yii::t('app_table', '用户id'),
            'wechat_id'     => Yii::t('app_table', '微信关联id'),
            'benefit_id'    => Yii::t('app_table', '被保险人id'),
            'amount'        => Yii::t('app_table', '保单金额'),
            'key'           => Yii::t('app_table', '键值，区分产品'),
            'type'          => Yii::t('app_table', '保障项目'),
            'remarks'       => Yii::t('app_table', '备注'),
            'start_time'    => Yii::t('app_table', '生效时间'),
            'end_time'      => Yii::t('app_table', '作废时间'),
            'created_at'    => Yii::t('app_table', '创建时间'),
            'updated_at'    => Yii::t('app_table', '修改时间'),
        ];
    }
}
